package cn.wolfcode.web.controller;

import cn.wolfcode.qo.JsonResult;
import cn.wolfcode.qo.QueryObject;
import cn.wolfcode.service.IPermissionService;
import cn.wolfcode.util.RequestPermission;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("/permission")
public class PermissionController {

    private IPermissionService permissionService;

    @Autowired
    public void setPermissionService(IPermissionService permissionService) {
        this.permissionService = permissionService;
    }

    @RequestMapping("/list")
    private String list(QueryObject qo, Model model){
        model.addAttribute("pageInfo",permissionService.query(qo));
        return "permission/list";
    }

    @RequestPermission(name = "重载权限",expression = "reload")
    @RequestMapping("/reload")
    @ResponseBody
    private JsonResult reload(QueryObject qo){
        permissionService.reload();
        return new JsonResult(true,"权限刷新失败");
    }
}
